/**
 * 
 */
package com.jinmei.mail.client;

import java.util.HashMap;
import java.util.Map;

import com.jinmei.mail.request.ExmailClientRequest;
import com.jinmei.remote.client.JHttpClient;
import com.jinmei.remote.response.JSONResponse;
import com.jinmei.remote.util.RequestUtils;

/**
 * @author richard
 *
 */
public class ExmailClientProxy {

    protected JHttpClient httpClient;

    public ExmailClientProxy(JHttpClient exmailClient) {
        this.httpClient = exmailClient;
    }

    public <T extends JSONResponse> T connectServer(
    		ExmailClientRequest request,
    		Class<T> responseClass) throws Exception {
        return connectServer(request, RequestUtils.HttpMethod.POST, responseClass);
    }

    public <T extends JSONResponse> T connectServer(
    		ExmailClientRequest request, String requestMethod, Class<T> responseClass) throws Exception {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put(RequestUtils.HeaderType.CONTENT_TYPE, RequestUtils.ContentType.URL_ENCODED);
        return httpClient.execute(request, headers, requestMethod, responseClass);
    }

}
